* VA Linux Systems Japan K.K.
*/
+#ifndef COMPAT
#include <xen/guest_access.h>
#include <xen/sched.h>
#include <public/xenoprof.h>
static void xenoprof_reset_buf(struct domain *d)
{
int j;
- struct xenoprof_buf *buf;
+ xenoprof_buf_t *buf;
if ( d->xenoprof == NULL )
{
buf = d->xenoprof->vcpu[j].buffer;
if ( buf != NULL )
{
- buf->event_head = 0;
- buf->event_tail = 0;
+ xenoprof_buf(d, buf, event_head) = 0;
+ xenoprof_buf(d, buf, event_tail) = 0;
}
}
}
for_each_vcpu ( d, v )
nvcpu++;
+ bufsize = sizeof(struct xenoprof_buf);
+ i = sizeof(struct event_log);
+#ifdef CONFIG_COMPAT
+ d->xenoprof->is_compat = IS_COMPAT(is_passive ? dom0 : d);
+ if ( XENOPROF_COMPAT(d->xenoprof) )
+ {
+ bufsize = sizeof(struct compat_oprof_buf);
+ i = sizeof(struct compat_event_log);
+ }
+#endif
+
/* reduce max_samples if necessary to limit pages allocated */
max_bufsize = (MAX_OPROF_SHARED_PAGES * PAGE_SIZE) / nvcpu;
- max_max_samples = ( (max_bufsize - sizeof(struct xenoprof_buf)) /
- sizeof(struct event_log) ) + 1;
+ max_max_samples = ( (max_bufsize - bufsize) / i ) + 1;
if ( (unsigned)max_samples > max_max_samples )
max_samples = max_max_samples;
- bufsize = sizeof(struct xenoprof_buf) +
- (max_samples - 1) * sizeof(struct event_log);
+ bufsize += (max_samples - 1) * i;
npages = (nvcpu * bufsize - 1) / PAGE_SIZE + 1;
d->xenoprof->rawbuf = alloc_xenheap_pages(get_order_from_pages(npages));
i = 0;
for_each_vcpu ( d, v )
{
+ xenoprof_buf_t *buf = (xenoprof_buf_t *)&d->xenoprof->rawbuf[i * bufsize];
+
d->xenoprof->vcpu[v->vcpu_id].event_size = max_samples;
- d->xenoprof->vcpu[v->vcpu_id].buffer =
- (struct xenoprof_buf *)&d->xenoprof->rawbuf[i * bufsize];
- d->xenoprof->vcpu[v->vcpu_id].buffer->event_size = max_samples;
- d->xenoprof->vcpu[v->vcpu_id].buffer->vcpu_id = v->vcpu_id;
+ d->xenoprof->vcpu[v->vcpu_id].buffer = buf;
+ xenoprof_buf(d, buf, event_size) = max_samples;
+ xenoprof_buf(d, buf, vcpu_id) = v->vcpu_id;
i++;
/* in the unlikely case that the number of active vcpus changes */
void xenoprof_log_event(
struct vcpu *vcpu, unsigned long eip, int mode, int event)
{
+ struct domain *d = vcpu->domain;
struct xenoprof_vcpu *v;
- struct xenoprof_buf *buf;
+ xenoprof_buf_t *buf;
int head;
int tail;
int size;
/* ignore samples of un-monitored domains */
/* Count samples in idle separate from other unmonitored domains */
- if ( !is_profiled(vcpu->domain) )
+ if ( !is_profiled(d) )
{
others_samples++;
return;
}
- v = &vcpu->domain->xenoprof->vcpu[vcpu->vcpu_id];
+ v = &d->xenoprof->vcpu[vcpu->vcpu_id];
/* Sanity check. Should never happen */
if ( v->buffer == NULL )
return;
}
- buf = vcpu->domain->xenoprof->vcpu[vcpu->vcpu_id].buffer;
+ buf = v->buffer;
- head = buf->event_head;
- tail = buf->event_tail;
+ head = xenoprof_buf(d, buf, event_head);
+ tail = xenoprof_buf(d, buf, event_tail);
size = v->event_size;
/* make sure indexes in shared buffer are sane */
if ( (head == tail - 1) || (head == size - 1 && tail == 0) )
{
- buf->lost_samples++;
+ xenoprof_buf(d, buf, lost_samples)++;
lost_samples++;
}
else
{
- buf->event_log[head].eip = eip;
- buf->event_log[head].mode = mode;
- buf->event_log[head].event = event;
+ xenoprof_buf(d, buf, event_log[head].eip) = eip;
+ xenoprof_buf(d, buf, event_log[head].mode) = mode;
+ xenoprof_buf(d, buf, event_log[head].event) = event;
head++;
if ( head >= size )
head = 0;
- buf->event_head = head;
+ xenoprof_buf(d, buf, event_head) = head;
if ( is_active(vcpu->domain) )
active_samples++;
else
passive_samples++;
if ( mode == 0 )
- buf->user_samples++;
+ xenoprof_buf(d, buf, user_samples)++;
else if ( mode == 1 )
- buf->kernel_samples++;
+ xenoprof_buf(d, buf, kernel_samples)++;
else
- buf->xen_samples++;
+ xenoprof_buf(d, buf, xen_samples)++;
}
}
return 0;
}
+#endif /* !COMPAT */
+
static int xenoprof_op_get_buffer(XEN_GUEST_HANDLE(void) arg)
{
struct xenoprof_get_buffer xenoprof_get_buffer;
return ret;
}
+#if defined(CONFIG_COMPAT) && !defined(COMPAT)
+#include "compat/xenoprof.c"
+#endif
+
/*
* Local variables:
* mode: C
#ifndef __XEN_XENOPROF_H__
#define __XEN_XENOPROF_H__
+#include <xen/config.h>
#include <public/xenoprof.h>
#include <asm/xenoprof.h>
#define XENOPROF_READY 2
#define XENOPROF_PROFILING 3
+#ifndef CONFIG_COMPAT
+typedef struct xenoprof_buf xenoprof_buf_t;
+#else
+#include <compat/xenoprof.h>
+typedef union {
+ struct xenoprof_buf native;
+ struct compat_oprof_buf compat;
+} xenoprof_buf_t;
+#endif
+
struct xenoprof_vcpu {
int event_size;
- struct xenoprof_buf *buffer;
+ xenoprof_buf_t *buffer;
};
struct xenoprof {
int domain_type;
int domain_ready;
int is_primary;
+#ifdef CONFIG_COMPAT
+ int is_compat;
+#endif
struct xenoprof_vcpu vcpu [MAX_VIRT_CPUS];
};
+#ifndef CONFIG_COMPAT
+#define XENOPROF_COMPAT(x) 0
+#define xenoprof_buf(d, b, field) ((b)->field)
+#else
+#define XENOPROF_COMPAT(x) ((x)->is_compat)
+#define xenoprof_buf(d, b, field) (*(!(d)->xenoprof->is_compat ? \
+ &(b)->native.field : \
+ &(b)->compat.field))
+#endif
+
struct domain;
void free_xenoprof_pages(struct domain *d);